// pages/user/user.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: null,
        memberInfo: {
            level: '黄金等级',
            coupons: {
                takeout: '?',
                meituan: '?',
                hotel: '?'
            }
        },
        loginUserInfo: null,
        menuList: [
            { id: 1, name: '我的订单', icon: '/images/order.png', url: '/pages/cart/cart' },
            { id: 2, name: '我的评价', icon: '/images/review.png', url: '/pages/order/order' },
            { id: 3, name: '售后服务', icon: '/images/service.png', url: '/pages/service/service' },
            { id: 4, name: '浏览记录', icon: '/images/history.png', url: '/pages/history/history' },
            { id: 5, name: '联系客服', icon: '/images/service.png', handler: 'contactService' }
        ]
    },

    handleMenuClick(e) {
        const { url, handler } = e.currentTarget.dataset;
        if (handler) {
            this[handler]();
        } else if (url) {
            if (url === '/pages/cart/cart' || url === '/pages/order/order') {
                wx.switchTab({
                    url,
                    fail: () => {
                        wx.showToast({
                            title: '页面跳转失败',
                            icon: 'none'
                        });
                    }
                });
            } else {
                wx.navigateTo({
                    url,
                    fail: () => {
                        wx.showToast({
                            title: '页面跳转失败',
                            icon: 'none'
                        });
                    }
                });
            }
        }
    },


    // 退出登录
    logout() {
        wx.showModal({
            title: '提示',
            content: '确定要退出登录吗？',
            success: (res) => {
                if (res.confirm) {
                    wx.clearStorageSync();
                    wx.reLaunch({
                        url: '/pages/login/login'
                    });
                }
            }
        });
    }
});